package io.p2p.stream.stun.protocol;

import io.p2p.stream.stun.handler.*;

import java.util.HashMap;
import java.util.Map;

public class UdpProtocolManagerFactory {
    private static final Map<String, StunBaseHandler> protocolMapping = new HashMap<>();

    static{
        protocolMapping.put(MainlineLoginAckHandler.commandType,new MainlineLoginAckHandler());
        protocolMapping.put(MainlineHeartbeatAckHandler.commandType,new MainlineHeartbeatAckHandler());
        protocolMapping.put(io.p2p.stream.p2pstun.handler.NatCheckHandler.commandType,new io.p2p.stream.p2pstun.handler.NatCheckHandler());
        protocolMapping.put(NatCheckAckHandler.commandType,new NatCheckAckHandler());
    }

    public static StunBaseHandler getHandler(String protocol) {
        StunBaseHandler handlerClass = protocolMapping.get(protocol);

        if(handlerClass == null){
            throw new IllegalArgumentException("Unsupported protocol: " + protocol);
        }

        return handlerClass;
    }
}
